/**
 * @author Francesco di Dio
 * Date: 20/apr/2013
 * Titolo: Account.java
 * Versione: 
 */

/**
 * Copyright (c) 2013 Francesco di Dio.
 * tabuto83@gmail.com 
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package com.tabuto.jkeys.models;

/**
 * 
 * @author tabuto83
 * 
 */
public final class Account extends AbstractJKeyModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 953531952761735497L;

	private final String username;

	private final String password;

	private final String url;

	private final String notes;

	private static final Account EMPTY_ACCOUNT_TO_GET = new Account.Builder("")
			.build();

	public static class Builder {
		/*
		 * Mandatory
		 */
		private String name;

		/*
		 * Optional
		 */
		private String username = "";

		private String password = "";

		private String url = "";

		private String notes = "";

		public Builder(String name) {
			this.name = (name != null ? name : "");
		}

		public Builder username(String username) {
			this.username = (username != null ? username : "");
			return this;
		}

		public Builder password(String password) {
			this.password = (password != null ? password : "");
			return this;
		}

		public Builder url(String url) {
			this.url = (url != null ? url : "");
			return this;
		}

		public Builder notes(String notes) {
			this.notes = (notes != null ? notes : "");
			return this;
		}

		public Account build() {
			return new Account(this);
		}

	}

	private Account(Builder builder) {
		this.setName(builder.name);
		this.username = builder.username;
		this.password = builder.password;
		this.url = builder.url;
		this.notes = builder.notes;
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public String getUrl() {
		return url;
	}

	public String getNotes() {
		return notes;
	}

	public static Account NEW_EMPTY_ACCOUNT() {
		return EMPTY_ACCOUNT_TO_GET;
	}

	@Override
	public int hashCode() {
		int result = 17;
		result = 31 * result + getUsername().hashCode();
		result = 31 * result + getPassword().hashCode();
		result = 31 * result + getUrl().hashCode();
		result = 31 * result + getNotes().hashCode();
		result = 31 * result + getName().hashCode();
		result = 31 * result + getId();
		return result;
	}

	@Override
	public boolean equals(Object o) {
		if (o == null)
			return false;
		if (!(o instanceof Account))
			return false;

		Account toEvalue = (Account) o;

		return (this.getUsername().equals(toEvalue.getUsername())
				&& this.getPassword().equals(toEvalue.getPassword())
				&& this.getName().equals(toEvalue.getName())
				&& this.getNotes().equals(toEvalue.getNotes())
				&& this.getUrl().equals(toEvalue.getUrl()) && this.getId() == toEvalue
				.getId());

	}

	@Override
	public String toString() {
		return "Account: " + getName();
		// return "Account [username=" + username + ", password=" + password
		// + ", url=" + url + ", notes=" + notes + ", getId()=" + getId()
		// + ", getName()=" + getName() + "]";
	}

}
